package com.nuanshui.heatedloan.credit.service.third.party;

import com.nuanshui.framework.consts.TransactionManagerType;
import com.nuanshui.heatedloan.constant.ServiceConstant;
import com.nuanshui.heatedloan.credit.dal.mapper.OptionalAuthMapper;
import com.nuanshui.heatedloan.credit.facade.third.party.CreditCardAuthService;
import com.nuanshui.heatedloan.credit.form.CustomerCreditCardInfoForm;
import com.nuanshui.heatedloan.credit.service.CustomerBankCardInfoServiceImpl;
import com.nuanshui.heatedloan.credit.vo.CustomerCreditCardInfoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by wangxw on 2017/7/8.
 */
@Service(ServiceConstant.CREDITCARDAUTHSERVICE)
@Transactional(readOnly=true,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER)
public class CreditCardAuthServiceImpl implements CreditCardAuthService {

    private  static  final Logger logger= LoggerFactory.getLogger(CustomerBankCardInfoServiceImpl.class);

    @Autowired
    private OptionalAuthMapper  optionalAuthMapper;

    @Override
    @Transactional(readOnly=false,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER)
    public Map<String, Object> creditCardAuth(CustomerCreditCardInfoForm customerCreditCardInfoForm) {
        Map<String, Object> maps=new HashMap<String,Object>();
        this.saveCustomerCreditCardInfo(customerCreditCardInfoForm);
        maps.put("authFalg",1);
        maps.put("authDesc","认证成功");
        return maps;
    }

    @Override
    @Transactional(readOnly=false,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER)
    public CustomerCreditCardInfoForm saveCustomerCreditCardInfo(CustomerCreditCardInfoForm customerCreditCardInfoForm) {
        optionalAuthMapper.saveCustomerCreditCardInfo(customerCreditCardInfoForm);
        return customerCreditCardInfoForm;
    }
    @Override
    public CustomerCreditCardInfoVO loadVOByUserId(String userId){
        return optionalAuthMapper.loadCustomerCreditCardInfoVOBuUserId(userId);
    }

    public List<CustomerCreditCardInfoVO> loadCreditCardAll(){
        List<CustomerCreditCardInfoVO> customerCreditCardInfoVOs=new ArrayList<CustomerCreditCardInfoVO>();
        customerCreditCardInfoVOs=optionalAuthMapper.loadCreditCardAll();
        return customerCreditCardInfoVOs;
    }

}
